From 43598fc5f2ed2bc1b1655b593172b8378cb1cfce Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 13 Mar 2020 08:56:56 +0100 Subject: [PATCH] broadway: Ensure images are decoded, not only loaded In firefox, onload will trigger when the image is loaded, but at that point it may not be decoded yet so showing it will sometimers trigger flashes. We use the new decode() feature instead which ensures both that the image is loaded *and* decoded, thus fixing the flashes. --- gdk/broadway/broadway.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js index 2478aacc7c..5b8311427c 100644 --- a/gdk/broadway/broadway.js +++ b/gdk/broadway/broadway.js @@ -274,6 +274,7 @@ function Texture(id, data) { var image = new Image(); image.src = this.url; this.image = image; + this.decoded = image.decode(); textures[id] = this; } @@ -1237,16 +1238,14 @@ function handleOutstanding() outstandingDisplayCommands = display_commands; if (new_textures.length > 0) { - var n_textures = new_textures.length; + var decodes = []; for (var i = 0; i < new_textures.length; i++) { - var t = new_textures[i]; - t.image.onload = function() { - n_textures -= 1; - if (n_textures == 0) { - handleOutstandingDisplayCommands(); - } - }; + decodes.push(new_textures[i].decoded); } + Promise.allSettled(decodes).then( + () => { + handleOutstandingDisplayCommands(); + }); } else { handleOutstandingDisplayCommands(); } -- 2.30.2